//
//  ViewController.m
//  创建按钮通过代码
//
//  Created by song on 15/1/3.
//  Copyright (c) 2015年 song. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    UIButton *btn = [[UIButton alloc]init];
    
    [self.view addSubview:btn];
    btn.frame =CGRectMake(50,50, 100, 100);
    UIImage *img =[UIImage imageNamed:@"test"];
    [btn setBackgroundImage:img forState:UIControlStateNormal];
    [btn setTitle:@"摸我" forState:UIControlStateNormal];
    UIImage *himg =[UIImage imageNamed:@"test1"];
    [btn setBackgroundImage:himg forState:UIControlStateHighlighted];
    [btn setTitle:@"dot mo" forState:UIControlStateHighlighted];
    
    UIButton *addbtn = [UIButton buttonWithType:UIButtonTypeContactAdd];
    [self.view addSubview:addbtn];
    addbtn.frame = CGRectMake(160  , 160, 100, 100);
    [addbtn addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
    [btn addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
    
    // Do any additional setup after loading the view, typically from a nib.
}

-(void)click:(UIButton *)btn
{
    NSString *title = btn.titleLabel.text;
    NSLog(@" %@ is click !!", title);
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
